package com.neuedu.elm.dao.Impl;

import com.neuedu.elm.dao.IAdminDao;
import com.neuedu.elm.po.Admin;
import com.neuedu.elm.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl implements IAdminDao {
    @Override
    public Admin login(String name, String passWord) {
        PreparedStatement ps = null;
        Connection connection = DBUtil.getConnection();
        ResultSet rs = null;
        Admin admin = new Admin();
        String sql = "select adminId,adminName,password from admin where adminName=? and password=?";
        try {
            ps = connection.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, passWord);
            rs = ps.executeQuery();
            while (rs.next()) {
//                int adminId = rs.getInt("adminId");
//                String adminName = rs.getString("adminName");
//                String password = rs.getString("password");
//                admin = new Admin(adminId, adminName, password);
                admin.setAdminId(rs.getInt("adminId"));
                admin.setAdminName(rs.getString("adminName"));
                admin.setPassword(rs.getString("password"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        DBUtil.close(ps, connection);
        return admin;
    }
}
